home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / comm / tcp / Socks5.lha / Socks5 / src / include / block.h next >
C/C++ Source or Header  |  1999-03-10  |  3KB  |  79 lines

  1. /* Copyright (c) 1995-1999 NEC USA, Inc.  All rights reserved.               */
  2. /*                                                                           */
  3. /* The redistribution, use and modification in source or binary forms of     */
  4. /* this software is subject to the conditions set forth in the copyright     */
  5. /* document ("Copyright") included with this distribution.                   */
  6.  
  7. /*
  8.  * $Id: block.h,v 1.6.4.1 1999/02/03 22:34:48 steve Exp $
  9.  */
  10.  
  11. #ifndef BLOCK_H
  12. #define BLOCK_H
  13.  
  14. #if defined(HAVE_FCNTL_H) || defined(HAVE_SYS_FCNTL_H)
  15. #ifdef HAVE_FCNTL_H
  16. #include <fcntl.h>
  17. #endif
  18.  
  19. #ifdef HAVE_SYS_FCNTL_H
  20. #include <sys/fcntl.h>
  21. #endif
  22.  
  23. /* some nonblock derivative                                                  */
  24. #ifdef O_NONBLOCK
  25. #define S5_NONBLOCK O_NONBLOCK
  26. #elif defined(FNONBLOCK)
  27. #define S5_NONBLOCK FNONBLOCK
  28. #elif defined(FNONBLK)
  29. #define S5_NONBLOCK FNONBLK
  30. #else
  31. #define S5_NONBLOCK 0
  32. #endif
  33.  
  34. /* some ndelay derivative                                                    */
  35. #ifdef O_NDELAY
  36. #define S5_NDELAY O_NDELAY
  37. #elif defined(FNDELAY)
  38. #define S5_NDELAY FNDELAY
  39. #else
  40. #define S5_NDELAY 0
  41. #endif
  42.  
  43. /* pick nonblock first when making things nonblocking -- it's posix          */
  44. /* if it doesn't exist, ndelay will work ok...                               */
  45. /* #if S5_NONBLOCK != 0       */
  46. /* #define NBFLAG S5_NONBLOCK */
  47. /* #else                      */
  48. /* #define NBFLAG S5_NDELAY   */
  49. /* #endif                     */
  50.  
  51. /* this is just to see if it is nonblocking.  We don't care which is set     */
  52. /* #define NBFLAGS (S5_NONBLOCK | S5_NDELAY)                                 */
  53.  
  54. #define ISNBLOCK(fd)        (fcntl((fd), F_GETFL, 0) & (S5_NONBLOCK | S5_NDELAY))
  55. #define ISBLOCK(fd)         (!ISNBLOCK((fd)))
  56.  
  57. /* #define GETFLAGS(fd, flags) (flags = fcntl((fd), F_GETFL, 0))                     */
  58.  
  59. /* #define BLOCK(fd, flags, nflags) do {                                           \ */
  60. /*     GETFLAGS((fd), (flags)); (nflags) = (flags);                                \ */
  61. /*     if (ISNBLOCK((flags))) fcntl((fd), F_SETFL, (nflags) = (flags) & ~NBFLAGS); \ */
  62. /* } while (0) */
  63.  
  64. /* #define UNBLOCK(fd, flags, nflags) do {                                         \ */
  65. /*     GETFLAGS((fd), (flags)); (nflags) = (flags);                                \ */
  66. /*     if (ISBLOCK((flags))) fcntl((fd), F_SETFL, (nflags) = (flags) | NBFLAG);    \ */
  67. /* } while (0) */
  68.  
  69. /* #define RSTBLOCK(fd, flags, nflags)                          \ */
  70. /*     if ((flags) != (nflags)) fcntl((fd), F_SETFL, (flags))     */
  71.  
  72. #else
  73.  
  74. #define ISNBLOCK(fd)  0
  75. #define ISBLOCK(fd)   1
  76.  
  77. #endif
  78. #endif
  79.